package com.qfedu.entity.course01;

public class Cycle {
    public boolean detectCycle(Node<Integer> head) {
        Node<Integer> fast = head;
        Node<Integer> slow = head;
        while (fast != null && fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;
            if (fast == slow) break;
        }
        if (fast == null || fast.next == null)
            return false;
        else
            return true;
    }
}
